home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / BARNET / COMPILER / SATHER / !Sather / Library / Base / test / sa / int < prev    next >
Text File  |  1996-05-08  |  3KB  |  89 lines

  1. ---------------------------> Sather 1.1 source file <--------------------------
  2. -- test_int.sa: 
  3. -- Author: Benedict A. Gomes <gomes@samosa.ICSI.Berkeley.EDU>
  4. -- Copyright (C) 1995, International Computer Science Institute
  5. -- $Id: int_test.sa,v 1.4 1996/05/08 08:34:43 borisv Exp $
  6. --
  7. -- COPYRIGHT NOTICE: This code is provided WITHOUT ANY WARRANTY
  8. -- and is subject to the terms of the SATHER LIBRARY GENERAL PUBLIC
  9. -- LICENSE contained in the file: Sather/Doc/License of the
  10. -- Sather distribution. The license is also available from ICSI,
  11. -- 1947 Center St., Suite 600, Berkeley CA 94704, USA.
  12. -------------------------------------------------------------------
  13. class TEST_INT is
  14.     include TEST;
  15.     
  16.    main is
  17.       class_name("INT");
  18.       a ::= 5;
  19.       b ::= 7;
  20.       tp: FSTR := #;
  21.       restp ::= 1101.str_in(tp,10,8,'#');
  22.       test("1101.str_in",restp,"######2115");
  23.       tp2: FSTR := #;
  24.       restp2 ::= 1101.str_in(tp2,10,16,'#');
  25.       test("1101.str_in(hex)",restp2,"#######44D");
  26.       tp3: FSTR := #;
  27.       restp3 ::= INT::nil.str_in(tp3,12,10,'#');
  28.       test("nil.str_in(10)",restp3,"#-2147483648");
  29.       
  30.       tp4: FSTR := #;
  31.       restp4 ::= INT::nil.str_in(tp4,12,16,'#');
  32.       test("nil.str_in(16)",restp4,"###-80000000");
  33.       tp5: FSTR := #;
  34.       restp5 ::= INT::nil.str_in(tp5,16,8,'#');
  35.       test("nil.str_in(16)",restp5,"####-20000000000");
  36.       
  37.       val ::= a.plus(b);
  38.       test("plus",val.str,"12");
  39.       test("plus",(a+b).str,"12");
  40.       test("minus",(a-b).str,"-2");
  41.       test("negate",(-a).str,"-5");
  42.       test("times",(a*b).str,"35");
  43.       test("div",(b/a).str,"1");
  44.       test("mod",(b.mod(a)).str,"2");
  45.       test("is_eq",(b=a).str,"false");
  46.       test("is_eq",(a=a).str,"true");
  47.       -- neq --- missing routines...
  48.       -- ...
  49.       -- Iter routines
  50.       i::=0; loop 9.times!; i:= i+1; end;
  51.       test("times!",i.str,"9");
  52.       res::="";  loop res := res+5.times!+" "; end;
  53.       test("times!:SAME",res,"0 1 2 3 4 ");
  54.       res:="";  loop res := res+5.for!(4)+" "; end;
  55.       test("for!",res,"5 6 7 8 ");
  56.       res:="";  loop res := res+5.upto!(10)+" "; end;
  57.       test("upto!",res,"5 6 7 8 9 10 ");
  58.       res:="";  loop res := res+5.downto!(1)+" "; end;
  59.       test("downto",res,"5 4 3 2 1 ");
  60.       res:="";  loop res := res+5.step!(3,4)+" "; end;
  61.       test("step",res,"5 9 13 ");
  62.       i:=0; loop i := 0.sum!(5.step!(3,4)); end;
  63.       test("sum!",i.str,"27");
  64.       i:=0; loop i := 0.product!(5.step!(3,4)); end;
  65.       test("product!",i.str,"585");
  66.       res:=""; loop res := res+1.stepto!(10,2)+" "; end;
  67.       test("stepto!",res.str,"1 3 5 7 9 ");
  68.       res:=""; loop res := res+0.stepto!(10,2)+" "; end;
  69.       test("stepto!",res.str,"0 2 4 6 8 10 ");      
  70.       res:=""; loop res := res+10.stepto!(0,-2)+" "; end;
  71.       test("step(down)to!",res.str,"10 8 6 4 2 0 ");
  72.     
  73.       test("pow 2^8",2.pow(8).str,256.str);
  74.       cur ::= 0;
  75.       cur_pow ::= 1;
  76.       loop
  77.      30.times!;
  78.      test("pow 2^"+cur,2.pow(cur).str,cur_pow.str);
  79.      cur := cur + 1;
  80.      cur_pow := cur_pow*2;
  81.       end;
  82.     
  83.       finish;
  84.    end;
  85.     
  86. end; -- class TEST_INT
  87.  
  88. -------------------------------------------------------------------
  89.